package com.gzz.demo.pattern.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * 观察对象
 * 必改
 */
public class Subject {
    private List<IObserver> observers = new ArrayList<IObserver>();
    private int state;

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
        notifyAllObservers();
    }

    public void attach(IObserver observer){
        observers.add(observer);
    }

    public void notifyAllObservers(){
        for (IObserver observer : observers) {
            observer.update();
        }
    }
}
